cmake_minimum_required(VERSION 2.8)
project("rezervilo")
message("Start prepare build.")
if(DEFINED BTARGET)
        message("Build target exist.")
else()
        message("Build target not exist. Set up taget \"all\"")
        set(BTARGET "all")
endif()

if(${BTARGET} STREQUAL "server")
        message("Target: server")
        add_subdirectory( qxmlrpc qxmlrpc )
        add_subdirectory( server server )
elseif(${BTARGET} STREQUAL "client")
        message("Target: client")
        add_subdirectory( qxmlrpc qxmlrpc )
        add_subdirectory( client client )
        add_subdirectory( plugins/repts/report_event rept_event)
        add_subdirectory( plugins/repts/report_events rept_events)
        add_subdirectory( plugins/repts/report_user rept_user)
        add_subdirectory( plugins/repts/report_users rept_users)
elseif(${BTARGET} STREQUAL "all")
        message("Target: all")
        add_subdirectory( qxmlrpc qxmlrpc )
        add_subdirectory( server server )
        add_subdirectory( client client )
        add_subdirectory( plugins/repts/report_event rept_event)
        add_subdirectory( plugins/repts/report_events rept_events)
        add_subdirectory( plugins/repts/report_user rept_user)
        add_subdirectory( plugins/repts/report_users rept_users)
endif()

message("Stop prepare build.")



exec_program(
    "git"
    ${CMAKE_CURRENT_SOURCE_DIR}
    ARGS "rev-parse HEAD"
    OUTPUT_VARIABLE VERSION )

string(SUBSTRING ${VERSION} 0 7 GIT_HASH)
configure_file(def.h.in def.h)


#uninstall for linux
if(${CMAKE_SYSTEM_NAME} STREQUAL Linux)
CONFIGURE_FILE(
        "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
        "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
        IMMEDIATE @ONLY)
ADD_CUSTOM_TARGET(uninstall
        "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
endif()

#uninstall for mac
if(${CMAKE_SYSTEM_NAME} STREQUAL Darwin)
CONFIGURE_FILE(
        "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
        "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
        IMMEDIATE @ONLY)
ADD_CUSTOM_TARGET(uninstall
        "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
endif()
